package com.crazyread.dao;

import com.crazyread.comment.lang.Result;
import com.crazyread.model.domain.Book;
import com.crazyread.model.domain.BookChapter;
import com.crazyread.model.domain.BookType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BooksMapper {
    //    查找全部书籍
    public List<Book> selectByBook();

    @Select("select * from book where id = #{id}")
    public Book selectBookById(int id);
    //模糊查询书籍
    @Select("select * from book where bookname like '%${bookname}%'")
    public List<Book> selectBookByName(String bookname);
    //    查找章节
    @Select("select * from book_chapter where id = #{id}")
    public List<BookChapter> selectByChapter();
    //    bookId查询该书下所有章节
    @Select("select * from book_chapter  where book_id = #{id} order by what_chapter asc")
    public List<BookChapter> selectByIdChapter(int id);
    //id查询该章节
    @Select("select * from book_chapter where id = #{id}")
    public BookChapter selectChapterById(int id);
    //    查询分类
    @Select("select * from book_type where id = #{id}")
    public BookType selectByIdType(int id);

    //    修改书籍
    public Book updateByIdBook(Book book);

    //随机查询多条数据
    @Select("SELECT * FROM book ORDER BY RAND() LIMIT 4")
    public List<Book> selectRandom();

    //    id添加到书架
    @Select("INSERT INTO book_rack (book_id )VALUES (#{id})")
    public Book InsertByIdBookRank(int id);

    //id批量移出书架
    @Delete("DELETE FROM book_rack WHERE book_id = #{id}")
    public void deleteByIdbatchRankBook(int[] ids);

    //查询书架
    public List<Book> selectByRankBook();

    //id删除书籍
    public Result deleteByIdBook(int id);

    //删除书架中书籍
    @Delete("DELETE FROM book_rack WHERE book_id = #{bookId}")
    public void deleteBookRackById(int bookId);

}
